home *** CD-ROM | disk | FTP | other *** search
/ PC World Interactive 1 / PC World Interactive 1 - Nisan 1997.iso / nostalji / bbs / music / sbbook.arj / SBBOOK / SOURCE / TP / PLAYVOCM.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1993-11-23  |  4.5 KB  |  151 lines

  1. (*********************************************************************
  2. *
  3. *  PROGRAM NAME: PLAYVOCM.PAS
  4. *
  5. *  COMPILER:     Borland Turbo Pascal ver. 4 or later
  6. *
  7. *  DESCRIPTION: Plays a .VOC file from the conventional memory using
  8. *               the CT-VOICE.DRV driver (accessed from SBSIM).  To run
  9. *               the program, type the following at the command line:
  10. *
  11. *               PLAYVOCM FILENAME
  12. *
  13. *               Where FILENAME is the drive/path/filename of the .VOC
  14. *               file to play.
  15. *
  16. *  NOTE:        SBSIM driver must be loaded before running this program.
  17. *
  18. *  WARNING:     This program does NOT support files larger than 64KB!
  19. *
  20. *********************************************************************)
  21.  
  22. program playvocm;
  23. uses dos,crt;
  24.  
  25. const HEADER_OFFSET  = $1A;
  26. const VOC_MEM_DRIVER = $04;
  27.  
  28.  
  29. {$I drvrfunc.pas}
  30.  
  31. var Command:char;
  32.     UserQuit:boolean;
  33.     RetValue:simerr;
  34.     FileName:string;
  35.     FileHandle:integer;
  36.     F:file;
  37.     FSize   :longint;
  38.     Buffer:^byte;
  39.  
  40.  
  41. (********************************************************************)
  42. begin (* main *)
  43.  
  44. if paramcount <> 1  (* no. of parameters entered on command line *)
  45. then begin
  46.      writeln('Command line must contain EXACTLY ONE filename parameter!');
  47.      halt;   (* Terminate program *)
  48.      end;
  49.  
  50. (*--- SEE IF SBSIM DRIVER HAS LOADED --*)
  51. SIMint := FindDvr('SBSIM', $0103);  (* Get SBSIM's interrupt no. *)
  52. if SIMint = 0
  53. then begin
  54.      writeln('SBSIM driver not loaded!');
  55.      halt;   (* Terminate program *)
  56.      end;
  57.  
  58. (*--- SEE IF CT-VOICE.DRV DRIVER HAS LOADED -------*)
  59. if (GetDrvrs and VOC_MEM_DRIVER) <> VOC_MEM_DRIVER
  60. then begin
  61.      writeln('CT-VOICE.DRV not loaded!');
  62.      halt;  (* Terminate program *)
  63.      end;
  64.  
  65.  
  66. (*--- OPEN FILE SPECIFIED ON COMMAND LINE ------*)
  67. FileHandle := DosOpen(paramstr(1), ReadAccess);
  68. if (FileHandle = -1)
  69. then begin
  70.      writeln('FILE: ',paramstr(1), ' not successfully opened!');
  71.      halt;    (* Terminate program *)
  72.      end;
  73.  
  74. DosClose(FileHandle);
  75.  
  76. FileName:=paramstr(1);  (* copy to string with more space before modifying *)
  77. assign(F,Filename);
  78. reset(F,1);
  79.  
  80. (*--- GET THE FILE SIZE -------------------------*)
  81. Fsize := filesize(F);
  82. if Fsize > 65535
  83. then begin
  84.      writeln('File size > 64KB not supported!');
  85.      halt;  (* Terminate program *)
  86.      end;
  87.  
  88. seek(F, HEADER_OFFSET);
  89.  
  90. (*--- ALLOCATE BUFFER AND LOAD IT FROM FILE -----------*)
  91. getmem(Buffer, Fsize-HEADER_OFFSET);
  92. if Buffer = nil
  93. (*& ****  if ((Buffer = (char * ) malloc((size_t) Fsize)) == NULL) ******)
  94. then begin
  95.      writeln('Memory buffer not allocated!');
  96.      halt;  (* Terminate program *)
  97.      end;
  98.  
  99. (* Read the file, without header, into memory. *)
  100. blockread(F, Buffer^, Fsize-HEADER_OFFSET);
  101. close(F);                      (* Done with the file, close it! *)
  102.  
  103.  
  104. (*--- StartSnd() INITIALIZES THE CT-VOICE DRIVER -----------*)
  105. RetValue := StartSnd(MemVoice, Buffer, false, 0);
  106. if RetValue <> SIMerr_NoErr
  107. then begin
  108.      writeln('ERROR CALLING SBSIM: ', errorMsg[RetValue]);
  109.      freemem(Buffer, Fsize-HEADER_OFFSET);  (*  Deallocate memory *)
  110.      halt;  (* Terminate program *)
  111.      end;
  112.  
  113. (*--- PlaySnd() BEGINS PLAYING OF THE FILE ----------*)
  114. RetValue := PlaySnd(MemVoice);
  115. if RetValue <> SIMerr_NoErr
  116. then begin
  117.      writeln('ERROR CALLING SBSIM: ', errorMsg[RetValue]);
  118.      freemem(Buffer, Fsize-HEADER_OFFSET);  (* Deallocate memory *)
  119.      halt;  (* Terminate program *)
  120.      end;
  121.  
  122. clrscr;  (* Clear screen *)
  123. writeln(#10#10#10#10#10'     SELECT ONE OF THE FOLLOWING OR WAIT UNTIL DONE:');
  124. writeln('                   (P)ause');
  125. writeln('                   (R)esume');
  126. writeln('                   (Q)uit');
  127.  
  128. UserQuit := false;
  129.  
  130. (*--- PROCESS USER INTERACTION OR WAIT FOR SOUND TO STOP -----------*)
  131. repeat
  132.      if (keypressed)  (* Was a key pressed? *)
  133.      then begin
  134.           Command := upcase(readkey);  (* Get char that's in buffer *)
  135.           if Command = 'P'
  136.           then PauseSnd(MemVoice)
  137.           else if Command = 'R'
  138.           then ResumeSnd(MemVoice)
  139.           else if Command = 'Q'
  140.           then UserQuit := true;
  141.           end;
  142. (* Exit do-while loop if file is done playing or user typed 'Q' *)
  143. until (UserQuit = true) or (GetSndStat(MemVoice) = 0);
  144.  
  145. (*--- IF SOUND IS STILL PLAYING AND USER HIT 'Q', STOP THE SOUND ---*)
  146. if (GetSndStat(MemVoice) <> 0) and (UserQuit = true)
  147. then StopSnd(MemVoice);
  148.  
  149. freemem(Buffer, Fsize-HEADER_OFFSET);  (* Deallocate memory *)
  150.  
  151. end.